<%
var prePath = global.config.contextPath + global.config.viewPrefix;
%>
<nav class="navbar navbar-default navbar-fixed-top" id="pageHeader">
    <div class="container-fluid">
        <div class="navbar-header">
            <%  session.userData.logoUrl  %>
            <a class="navbar-brand" href="<%= prePath %>/" style="padding:0;">
                <img src="<%= global.config.publicPath %><%= session.userData.logoUrl %>"
                     style="height:52px;width:180px;position:relative;top:1px;left:-38px;"/>
            </a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <div style="margin-top: 18px;color: #eeeee;padding: 0 15px;">
                        <% if(session.userData.company.length>0) { %>
                        <select class="company-select">
                            <% if(session.userData.company) { for(var i = 0;i < session.userData.company.length;i++) { %>
                            <option value="<%= session.userData.company[i] %>"><%= session.userData.company[i] %></option>
                            <% }} %>
                        </select>
                        <% } %>
                    </div>
                </li>
                <li>
                    <div style="margin-top: 22px;color: #d9edf7;padding: 0 15px;" class="navMenu"
                         href="javascript:void(0);"><%= session.userData.orgCode?(session.userData.orgCode + session.userData.orgName):"" %></div>
                </li>
                <li><a class="navMenu" onclick="showUpdatePw();" title="<%= __('homepage.clickPassword') %>">
                        <em class="unzhehang" style="max-width: 250px;"><i class="glyphicon glyphicon-info-sign"></i><%= session.userData.userName %></em></a>
                </li>
                <li><a class="navMenu" href="<%= prePath %>/logout"><i class="fa fa-off"></i><%= __("homepage.exit") %></a></li>
            </ul>
            <ul class="nav navbar-nav navbar-left" style="margin-right: 10px;">
                <li class="index"><a href="<%= prePath %>/"><%= __("homepage.home") %></a></li>
                <% if(session.roleData){ for(var i = 0;i < session.roleData.length;i++) {
                    var tmp = session.roleData[i].split(':'), code;
                if(tmp[1].startsWith("_")){
                    code = tmp[1].substring(1);
                %>
                <li class="<%= code %>"><a href="<%= prePath %>/<%= code %>/"><%= __(tmp[1]) %></a></li>
                <% }}} %>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>
<div class="modal" id="password_win">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <span class="modal-title"><%= __('homepage.changePassword') %></span>
            </div>
            <div class="modal-body">
                <div class="tab-pane">
                    <form class="form-horizontal password-form">
                        <input type="hidden" name="id" value="<%= session.userData.userId %>">
                        <div class="form-group">
                            <label class="col-md-offset-1 col-md-2 control-label"><%= __('homepage.oldPassword') %></label>
                            <div class="col-md-6">
                                <input class="form-control" name="oldPw" id="oldPw" type="password"
                                       dol-validate="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-offset-1 col-md-2 control-label"><%= __('homepage.newPassword') %></label>
                            <div class="col-md-6">
                                <input class="form-control" name="newPw" id="newPw" type="password"
                                       dol-validate="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-offset-1 col-md-2 control-label"><%= __('homepage.repeatPassword') %></label>
                            <div class="col-md-6">
                                <input class="form-control" name="password" id="confirmPw" type="password"
                                       dol-validate="required">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary updatePw-btn" onclick="updatePw();"><%= __('account.save') %></button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><%= __('account.delete') %></button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<script>
    var showUpdatePw = function () {
        $('#password_win').modal('show');
    };
    var updatePw = function () {
        var formData = Dolphin.form.getValue('.password-form');
        if(formData.oldPw && formData.newPw && formData.password){
            if (formData.newPw == formData.password) {
                Dolphin.ajax({
                    url: '/api/10163eabd5b247b286bea0a879cf5892',
                    type: Dolphin.requestMethod.POST,
                    data: Dolphin.json2string(formData),
                    onSuccess: function (reData) {
                        $('#password_win').modal('hide');
                        location.href = "<%= prePath %>/logout";
                    }
                });
            } else {
                Dolphin.alert(Dolphin.i18n.get("homepage.inconsistent"));
            }
        }else{
            Dolphin.alert(Dolphin.i18n.get("homepage.essential"));
        }
    };
</script>